home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c++
- Subject: Re: Initalizing variables in a for loop
- Date: Tue, 16 Jan 1996 13:03:39 GMT
- Organization: Netcom
- Message-ID: <30fba161.37516992@nntp.ix.netcom.com>
- References: <st95h6e9-1501962022390001@myers1-006.resnet.drexel.edu>
- NNTP-Posting-Host: ix-dc6-24.ix.netcom.com
- X-NETCOM-Date: Tue Jan 16 5:03:31 AM PST 1996
- X-Newsreader: Forte Agent .99c/16.141
-
- st95h6e9@dunx1.ocs.drexel.edu (Luke Cassady-Dorion) wrote:
-
- |>When initalizing a variable in a for loop as in the example below
- does the
- |>compiler free up the memory allocated to that variable after the
- loop
- |>exits, thus making the variable unuseable by other parts of the
- function,
- |>or its it retined??
- |>
- |>
- |> for (int i=0; i < some_value, i++)
-
- According to the draft, i is local to the loop and is unavailable
- after the loop exits. Many compilers still use an older rule in which
- i remains in scope until the end of the enclosing block.
-
- Even in the first case, the memory for i may not be released until the
- function ends. Many compilers allocate all auto memory for a function
- when it is entered and release it when it exits. Such compilers
- usually will reuse memory for variables local to other inner blocks.
-
-
- Michael M Rubenstein
-